<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements.  See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership.  The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<ng-container *ngIf="taskManagerDetail">
  <nz-card nzTitle="Memory">
    <nz-card nzType="inner" nzTitle="JVM (Heap/Non-Heap)">
      <nz-table
        [nzTemplateMode]="true"
        [nzShowPagination]="false"
        [nzSize]="'small'"
        class="no-border">
        <thead>
          <tr>
            <th>Type</th>
            <th>Committed</th>
            <th>Used</th>
            <th>Maximum</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td><strong>Heap</strong></td>
            <td>{{ taskManagerDetail.metrics.heapCommitted | humanizeBytes }}</td>
            <td>{{ taskManagerDetail.metrics.heapUsed | humanizeBytes }}</td>
            <td>{{ taskManagerDetail.metrics.heapMax | humanizeBytes }}</td>
          </tr>
          <tr>
            <td><strong>Non-Heap</strong></td>
            <td>{{ taskManagerDetail.metrics.nonHeapCommitted | humanizeBytes }}</td>
            <td>{{ taskManagerDetail.metrics.nonHeapUsed | humanizeBytes }}</td>
            <td>{{ taskManagerDetail.metrics.nonHeapMax | humanizeBytes }}</td>
          </tr>
          <tr>
            <td><strong>Total</strong></td>
            <td>{{ (taskManagerDetail.metrics.heapCommitted + taskManagerDetail.metrics.nonHeapCommitted) | humanizeBytes }}</td>
            <td>{{ (taskManagerDetail.metrics.heapUsed + taskManagerDetail.metrics.nonHeapUsed) | humanizeBytes }}</td>
            <td>{{ (taskManagerDetail.metrics.heapMax + taskManagerDetail.metrics.nonHeapMax) | humanizeBytes }}</td>
          </tr>
        </tbody>
      </nz-table>
    </nz-card>
    <nz-card nzType="inner" nzTitle="Outside JVM">
      <nz-table
        [nzTemplateMode]="true"
        [nzShowPagination]="false"
        [nzSize]="'small'"
        class="no-border">
        <thead>
          <tr>
            <th>Type</th>
            <th>Count</th>
            <th>Used</th>
            <th>Capacity</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td><strong>Direct</strong></td>
            <td>{{ taskManagerDetail.metrics.directCount | number }}</td>
            <td>{{ taskManagerDetail.metrics.directUsed | humanizeBytes }}</td>
            <td>{{ taskManagerDetail.metrics.directMax | humanizeBytes }}</td>
          </tr>
          <tr>
            <td><strong>Mapped</strong></td>
            <td>{{ taskManagerDetail.metrics.mappedCount | number }}</td>
            <td>{{ taskManagerDetail.metrics.mappedUsed | humanizeBytes }}</td>
            <td>{{ taskManagerDetail.metrics.mappedMax | humanizeBytes }}</td>
          </tr>
        </tbody>
      </nz-table>
    </nz-card>
  </nz-card>
  <nz-card nzTitle="Network">
    <nz-card nzType="inner" nzTitle="Memory Segments">
      <nz-table
        [nzTemplateMode]="true"
        [nzShowPagination]="false"
        [nzSize]="'small'"
        class="no-border">
        <thead>
          <tr>
            <th>Type</th>
            <th>Count</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td><strong>Available</strong></td>
            <td>{{ taskManagerDetail.metrics.memorySegmentsAvailable | number }}</td>
          </tr>
          <tr>
            <td><strong>Total</strong></td>
            <td>{{ taskManagerDetail.metrics.memorySegmentsTotal | number }}</td>
          </tr>
        </tbody>
      </nz-table>
    </nz-card>
    <nz-card nzType="inner" nzTitle="Garbage Collection">
      <nz-table
        [nzTemplateMode]="true"
        [nzShowPagination]="false"
        [nzSize]="'small'"
        class="no-border">
        <thead>
          <tr>
            <th>Collector</th>
            <th>Count</th>
            <th>Time</th>
          </tr>
        </thead>
        <tbody>
          <tr *ngFor="let g of taskManagerDetail.metrics.garbageCollectors">
            <td><strong>{{ g.name }}</strong></td>
            <td>{{ g.count | number }}</td>
            <td>{{ g.time | number }}</td>
          </tr>
        </tbody>
      </nz-table>
    </nz-card>
  </nz-card>
</ng-container>
